import api from "../../api/sop";
import { toast, err } from "../../utils/wxapi";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 50,
    userId: wx.getStorageSync("userId"),
    pageTotal: 0,
    list: [],
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getlist();
  },
  async getlist() {
    try {
      const { page, limit, userId, list } = this.data;
      const res = await api.paylist({ page, limit, data: { userId } });
      console.log(res);
      if (res.respCode === 200) {
        const newlist = JSON.parse(res.source);
        this.setData({
          pageTotal: res.pageTotal,
          list: list.length === 0 ? newlist : list.concat(newlist),
        });
      }
    } catch (error) {
      err(error);
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const { list, page, pageTotal } = this.data;
    if (list.length >= pageTotal) return toast("已获取全部提现内容");
    this.setData({ page: page + 1 });
    this.getlist();
  },
});
